using UnityEngine;
using EveryFunc;
using System.Collections.Generic;
public class PlayerCircleDetect : MonoBehaviour
{
    private CircleCollider2D detectCollider;
    //交互物品列表
    public List<GameObject> interactList;
    private void Awake()
    {
        detectCollider = GetComponent<CircleCollider2D>();
    }
    private void Update() {
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Interactive"))
        {
            Debug.Log("检测到:"+other.gameObject.name);
            if (!interactList.Contains(other.gameObject))
            {
                interactList.Add(other.gameObject);
            }
        }
    }
    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Interactive"))
        {
            if (interactList.Contains(other.gameObject))
            {
                interactList.Remove(other.gameObject);
            }
        }
    }
    public void SortList(Vector3 tarPos)
    {
        interactList.Sort((s, x) => Vector3.Distance(s.transform.position, tarPos).CompareTo(Vector3.Distance(x.transform.position, tarPos)));
    }
}